#!/usr/bin/env python
"""Commandline utility to encode map properties into PNG heightmaps for 
Artillery
"""
__author__ = "Ragzouken"
__copyright__ = "Copyright (C) 2008 Ragzouken"
__license__ = "Public Domain"
__version__ = "1.0"

from PIL import Image, PngImagePlugin
from optparse import OptionParser

_PARSER = OptionParser()
_PARSER.add_option("-m", "--map", help="Encode properties into MAP.", 
	dest="map", metavar="MAP")
_PARSER.add_option("-t", "--terrain", help="Encode terrain as TERRAIN.", 
	dest="terrain", default="temperate", metavar="TERRAIN")
_PARSER.add_option("-s", "--scale", help="Encode scale as SCALE.", 
	dest="scale", default=8, type="int")
OPTIONS, ARGS = _PARSER.parse_args()

def encode(path, **kwargs):
	heightmap = Image.open(OPTIONS.map)
	meta = PngImagePlugin.PngInfo()
	
	for key, value in kwargs.iteritems():
		meta.add_text(key, str(value))
	
	heightmap.save(path, "png", pnginfo=meta)

if __name__ == '__main__':
	encode(OPTIONS.map, terrain=OPTIONS.terrain, scale=OPTIONS.scale)
